package io;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

/**
 * 字符转换流测试
 */
public class OutputStreamWriterTest {
    public static void main(String[] args) {
        writeUTF8();
        writeGBK();
    }

    private static void writeUTF8() {
        try (OutputStreamWriter osw = new OutputStreamWriter(
                new FileOutputStream("/Users/luchuan/IdeaProjects/java-test/utf8.txt"),
                "UTF-8")) {
            osw.write("你好呀");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void writeGBK() {
        try (OutputStreamWriter osw = new OutputStreamWriter(
                new FileOutputStream("/Users/luchuan/IdeaProjects/java-test/gbk.txt"),
                "GBK")) {
            osw.write("你好呀");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
